#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int thirdMax(vector<int>& nums)
    {
        int Max = INT_MIN;
        set<int> s;
        for (int i = 0;i < nums.size();++i)
        {
            Max = max(Max, nums[i]);
            s.insert(nums[i]);
        }
        if (s.size() < 3)
        {
            return Max;
        }
        for (int j = 0;j < 2;++j)
        {
            int wLine = Max;
            Max = INT_MIN;
            for (int i = 0;i < nums.size();++i)
            {
                if (nums[i] < wLine)
                {
                    Max = max(Max, nums[i]);
                }
            }
        }
        return Max;
    }
};